#pragma once

#include "IHttpResponse.h"

namespace Poco
{
	namespace Net
	{
		class HTTPServerResponse;
	};
};

namespace MiniHttpServer {
	ref class HttpResponse : public IHttpResponse
	{
	public:
		HttpResponse(Poco::Net::HTTPServerResponse& response);
		virtual ~HttpResponse();
		!HttpResponse();

		virtual void AddHeaderValue(System::String^ strKey, System::String^ strValue) override;

		virtual property System::Collections::Specialized::NameValueCollection^ Headers
		{
			System::Collections::Specialized::NameValueCollection^ get()  override{ return m_headers; };
		}

		virtual property System::String^ ContentType
		{
			System::String^ get()  override{ return m_contentType; };
			void set(System::String^ v) override { m_contentType = v; };
		}

		virtual property __int64 ContentLength
		{
			__int64 get()  override{ return m_contentLength; };
			void set(__int64 v) override { m_contentLength = v; }
		}

		virtual property bool KeepAlive 
		{ 
			bool get()  override { return m_keepAlive; };
			void set(bool v) override { m_keepAlive = v; };
		}

		virtual property System::Net::HttpStatusCode Status
		{
			System::Net::HttpStatusCode get()  override { return m_status; };
			void set(System::Net::HttpStatusCode status) override { SetStatus(status); };
		};

		virtual property bool Chunked
		{
			bool get() override { return m_chunked; };
			void set(bool v) override { m_chunked = v; };
		}

		virtual property System::String^ StatusDescription 
		{ 
			System::String^ get() override { return GetStatusDescription(); };	
		};

		virtual System::IO::Stream^ GetBody() override;
	private:
		void PrepareHeaders();
		void SetStatus(System::Net::HttpStatusCode status);;
		System::String^ GetStatusDescription();;

		Poco::Net::HTTPServerResponse& m_response;
		System::IO::Stream^ m_responseStream;

		__int64 m_contentLength;
		System::String^ m_contentType;
		bool m_keepAlive;
		System::Net::HttpStatusCode m_status;
		bool m_chunked;

		System::Collections::Specialized::NameValueCollection^ m_headers;
	};
};